﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataManager.BLL;

namespace FILMEK.GUI
{
    public partial class frmLogIn : Form
    {
        public FilmManager manager;

        /// <summary>
        /// Inicializalas.
        /// </summary>
        public frmLogIn(FilmManager manager)
        {
            InitializeComponent();
            this.manager = manager;
        }

        /// <summary>
        /// Felhasznalonev es jelszo ellenorzese es ennek fuggvenyeben tovabblepes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_LogIn_Click(object sender, EventArgs e)
        {
            //try
            //{
                string username = tb_FelhasznaloNev.Text;
                tb_FelhasznaloNev.Text = "";
                string password = tb_Jelszo.Text;
                tb_Jelszo.Text = "";

                //String j = this.HashString(tbJelszo.Text);
                if (cbAdmin.Checked)
                    {
                        if (manager.bejelentkezes(username, password, 1))
                        {
                            frmAdmin myfrmAdmin = new frmAdmin(manager);
                            this.Hide();
                            myfrmAdmin.ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Nem helyes felhasznalonev vagy jelszo!!!");
                        }
                    }

               else
                {
                    if (manager.bejelentkezes(username, password, 0))
                    {
                        //MessageBox.Show("ALkalmazott!!!");
                        int alkalmazottId = Convert.ToInt32(manager.getAlkalmazottIdByUserName(username).Tables[0].Rows[0][0]);
                        frmSzamla myfrmSzamla = new frmSzamla(this.manager, alkalmazottId);
                        this.Hide();
                        myfrmSzamla.ShowDialog();
                        this.Close();
                        
                    }
                    else
                    {
                        MessageBox.Show("Nem helyes felhasznalonev vagy jelszo!!!");
                    }
                }
            //}
            //catch
            //{
            //    MessageBox.Show("A szovegmezok nem voltak megfeleloen kitoltve!");
            //}
        }

        /// <summary>
        /// Belepes vasarlokent.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Vasarol_Click(object sender, EventArgs e)
        {
            frmMovies _frmMovies = new frmMovies(manager);
            this.Hide();
            _frmMovies.ShowDialog();
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
